Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data

Namespace DataAccess
    Public Class ProfileData
        Public Shared Sub Save(ByVal _Profile As ModelLayer.IProfile) 
            Using oDm As New DataManager()
                oDm.CommandType = CommandType.StoredProcedure
                oDm.Add("@Username ", SqlDbType.NVarChar, 50, _Profile.Username)
                oDm.Add("@LastName", SqlDbType.NVarChar, 50, _Profile.LastName)
                oDm.Add("@FirstName", SqlDbType.NVarChar, 50, _Profile.FirstName)
                oDm.Add("@Gender", SqlDbType.Char, 1, _Profile.Gender)
                oDm.Add("@City", SqlDbType.NVarChar, 50, _Profile.City)
                oDm.Add("@Address", SqlDbType.NVarChar, 50, _Profile.Address)
                oDm.Add("@State", SqlDbType.NVarChar, 50, _Profile.State)
                oDm.Add("@Zip", SqlDbType.NVarChar, 50, _Profile.Zip)
                oDm.Add("@Email", SqlDbType.NVarChar, 50, _Profile.Email)
                oDm.Add("@BirthDay", SqlDbType.DateTime, 50, _Profile.BirthDay)
                oDm.Add("@PhoneNumber", SqlDbType.VarChar, 15, _Profile.PhoneNumber)
                oDm.ExecuteNonQuery("stp_AddEditProfile")
            End Using
        End Sub
        Public Shared Sub Load(ByVal _Profile As ModelLayer.IProfile)
            Using oDm As New DataManager()
                oDm.CommandType = CommandType.StoredProcedure
                oDm.Add("@Username ", SqlDbType.NVarChar, 50, _Profile.Username)

                Dim dt As DataTable = oDm.ExecuteDataTable("stp_LoadProfile")
                If dt IsNot Nothing And dt.Rows.Count > 0 Then
                    _Profile.Address = dt.Rows(0)("Address").ToString()
                    _Profile.City = dt.Rows(0)("City").ToString()
                    _Profile.FirstName = dt.Rows(0)("FirstName").ToString()
                    _Profile.Gender = dt.Rows(0)("Gender").ToString()
                    _Profile.LastName = dt.Rows(0)("LastName").ToString()
                    _Profile.State = dt.Rows(0)("State").ToString()
                    _Profile.Zip = dt.Rows(0)("Zip").ToString()
                    _Profile.Email = dt.Rows(0)("Email").ToString()
                    If dt.Rows(0)("BirthDay") IsNot DBNull.Value Then
                        _Profile.BirthDay = DirectCast(dt.Rows(0)("BirthDay"), Date)
                    End If
                    _Profile.PhoneNumber = dt.Rows(0)("Phone").ToString()
                End If
            End Using
        End Sub
    End Class
End Namespace